//
//  FANComposeTools.swift
//  Weibo - Swift
//
//  Created by user on 16/4/25.
//  Copyright © 2016年 user. All rights reserved.
//

import UIKit

enum FANComposeToolBarButtonType: Int {
    case Picture = 0, Mention, Trend, Emoticon, Add
}

class FANComposeTools: UIStackView {
    
    var callBackClosure:((type:FANComposeToolBarButtonType)->())?

    override init(frame: CGRect) {
        super.init(frame: frame)
        
        setupUI()
        
        distribution = .FillEqually
        
        

    }
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func setupUI(){
        
//        backgroundColor = UIColor.redColor()
        
        addToolsButton("compose_toolbar_picture",type: .Picture)
        addToolsButton("compose_mentionbutton_background",type: .Mention)
        addToolsButton("compose_trendbutton_background",type: .Trend)
        addToolsButton("compose_emoticonbutton_background",type: .Emoticon)
        addToolsButton("compose_add_background",type: .Add)

    }
    
    func addToolsButton(imageName:String,type:FANComposeToolBarButtonType){
        
        let button = UIButton()
        
        button.tag = type.rawValue
        
        button.addTarget(self, action: "didClickButton:", forControlEvents: UIControlEvents.TouchUpInside)
        
        button.setImage(UIImage(named: imageName), forState: UIControlState.Normal)
        
        button.setImage(UIImage(named: "\(imageName)_highlighted"), forState: UIControlState.Highlighted)
        
        button.setBackgroundImage(UIImage(named: "compose_toolbar_background"), forState: UIControlState.Normal)
        
        button.setBackgroundImage(UIImage(named: "compose_toolbar_background"), forState: UIControlState.Highlighted)
        
//        button.sizeToFit()
        
        self.addArrangedSubview(button)
    }
    
    @objc func didClickButton(button:UIButton){
        
        callBackClosure?(type: FANComposeToolBarButtonType(rawValue: button.tag)!)
    }

}
